package org.jfbmonitor.view.attachment;

import java.text.DateFormat;
import java.util.List;
import javax.swing.table.AbstractTableModel;
import org.jfbmonitor.beans.Attachment;

public class AttachmentTableModel extends AbstractTableModel {	
	private static final long serialVersionUID = 1L;
	private List<Attachment> attachments;
	
	public AttachmentTableModel( List<Attachment> attachments ){
		this.attachments = attachments;
	}

	@Override
	public int getColumnCount() {		
		return 14;
	}

	@Override
	public int getRowCount() {		
		return this.attachments.size();
	}

	@Override
	public Object getValueAt( int rowIndex, int columnIndex ) {
		Attachment attachment = this.attachments.get(rowIndex);
		DateFormat dt = DateFormat.getDateTimeInstance();
		switch (columnIndex) {
		   case 0: return  attachment.getAttachmentId();
		   case 1: return  attachment.getServerPId();
		   case 2: return  attachment.getState();
		   case 3: return  attachment.getAttachmentName();
		   case 4: return  attachment.getUser();
		   case 5: return  attachment.getRole();
		   case 6: return  attachment.getRemoteProtocol();
		   case 7: return  attachment.getRemoteAddress();
		   case 8: return  attachment.getRemotePId();
		   case 9: return  attachment.getRemoteProcess();
		   case 10: return attachment.getCharacterSet();
		   case 11: return dt.format(attachment.getTimestamp());
		   case 12: return attachment.getGarbageCollection();
		   case 13: return attachment.getStatId(); 
		}		
		return null;
	}
	public Attachment getValuesAttachment( int rowIndex ){
		return attachments.get(rowIndex);
	}

}
